package com.xidian.GMS.service.impl;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.xidian.GMS.entity.Users;
import com.xidian.GMS.mapper.UsersMapper;
import com.xidian.GMS.service.LoginService;

@Service
public class LoginServiceImpl implements LoginService {

	@Autowired
	private UsersMapper usermapper;

	@Override
	public Users login(String Account, String password) {
		System.out.println(1);
		Users user = usermapper.selectByAccount(Account);
		System.out.println(user);
		if(user == null || ! password.equals(user.getPassword())){
			System.out.println("用户名密码错误");
			return user;
		}else{
			System.out.println("用户名密码正确");
			return user;
		}
	}

	@Override
	public boolean checkCode(HttpSession session, String code) {
		System.out.println(2);
		String codeSession = (String) session.getAttribute("code");  
		System.out.println("code");
		System.out.println(codeSession);
		System.out.println(code);
        if (StringUtils.isEmpty(codeSession)) {  
           System.out.println("没有生成验证码信息");
            return false; 
        }  
        if (StringUtils.isEmpty(code)) { 
        	System.out.println("未填写验证码信息");
            return  false;
       
        }  
        if (codeSession.equalsIgnoreCase(code)) {
        	System.out.println("验证码通过 ");
        	return true;
            // 验证码通过  
        } else {  
        	System.out.println("验证码错误");
            return false;  
        }  
		
	}
	
	
}
